package net.sk.china.city.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import net.sk.china.city.domain.dto.organization.OrganizationInfoDTO;
import net.sk.china.city.domain.dto.organization.OrganizationSearchDTO;
import net.sk.china.city.domain.dto.organization.OrganizationUpdateDTO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import net.sk.china.city.controller.base.BaseController;
import net.sk.china.city.domain.dto.AjaxResult;
import net.sk.china.city.service.IArCharitableOrganizationService;
import net.sk.china.city.domain.dto.TableDataInfo;

/**
 * 慈善机构Controller
 * 
 * @author ruoyi
 * @date 2024-04-07
 */
@Api(tags = "服务网点接口")
@RestController
@RequestMapping("/system/organization")
public class ArCharitableOrganizationController extends BaseController
{
    @Autowired
    private IArCharitableOrganizationService arCharitableOrganizationService;

    /**
     * 查询慈善机构列表
     */
    @ApiOperation("服务网点列表")
    @PreAuthorize("hasAnyAuthority('system:organization:list')")
    @GetMapping("/page")
    public TableDataInfo<OrganizationInfoDTO> page(OrganizationSearchDTO organizationSearchDTO)
    {
        startPage();
        return arCharitableOrganizationService.selectArCharitableOrganizationList(organizationSearchDTO);
    }

    @ApiOperation("服务网点选项")
    @GetMapping("/list")
    public AjaxResult list()
    {
        return success(arCharitableOrganizationService.selectOrganizationList());
    }

    /**
     * 导出慈善机构列表
     */
    @ApiOperation(value = "导出服务网点", hidden = true)
    @PreAuthorize("hasAnyAuthority('system:organization:export')")
    @PostMapping("/export")
    public void export(HttpServletResponse response, OrganizationSearchDTO organizationSearchDTO)
    {
        TableDataInfo<OrganizationInfoDTO> organizationInfoDTOTableDataInfo = arCharitableOrganizationService.selectArCharitableOrganizationList(organizationSearchDTO);
        List<OrganizationInfoDTO> list = organizationInfoDTOTableDataInfo.getRows();
//        ExcelUtil<OrganizationInfoDTO> util = new ExcelUtil<>(OrganizationInfoDTO.class);
//        util.exportExcel(response, list, "慈善机构数据");
    }

    /**
     * 获取慈善机构详细信息
     */
    @ApiOperation("获取服务网点详情")
    @PreAuthorize("hasAnyAuthority('system:organization:query')")
    @GetMapping(value = "/{pkId}")
    public AjaxResult getInfo(@PathVariable("pkId") Long pkId)
    {
        return success(arCharitableOrganizationService.selectArCharitableOrganizationByPkId(pkId));
    }

    /**
     * 新增慈善机构
     */
    @ApiOperation("新增服务网点")
    @PreAuthorize("hasAnyAuthority('system:organization:add')")
    @PostMapping
    public AjaxResult add(@RequestBody OrganizationUpdateDTO organizationUpdateDTO)
    {
        return toAjax(arCharitableOrganizationService.insertArCharitableOrganization(organizationUpdateDTO));
    }

    /**
     * 修改慈善机构
     */
    @ApiOperation("修改服务网点")
    @PreAuthorize("hasAnyAuthority('system:organization:edit')")
    @PutMapping
    public AjaxResult edit(@RequestBody OrganizationUpdateDTO organizationUpdateDTO)
    {
        return toAjax(arCharitableOrganizationService.updateArCharitableOrganization(organizationUpdateDTO));
    }

    /**
     * 删除慈善机构
     */
    @ApiOperation("删除服务网点")
    @PreAuthorize("hasAnyAuthority('system:organization:remove')")
	@DeleteMapping("/{pkIds}")
    public AjaxResult remove(@PathVariable Long[] pkIds)
    {
        return toAjax(arCharitableOrganizationService.deleteArCharitableOrganizationByPkIds(pkIds));
    }
}
